#coding = utf-8
import os

root = 'E://pics'
names = os.listdir(root)
delete = []
for name in names:
    if name[-3:] == 'txt':
        delete.append(name)
number = 0
while(1):
     try:
        path = root + '//' + delete[number]
        os.remove(path)
        print('删除成功')
        number += 1
     except:
         break